/* Generate the standard mask window.
 *
 * Copyright (c) 1993-2007 Leo Spiekman, Xaveer Leijtens, Martin Hill
 *
 * This file is part of libMask.
 *
 * libMask is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * libMask is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with libMask.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mask.h"

/* Window function maps onto var2window() */

void window(const char *title) {
  char fulltitle[100];

  strcpy(fulltitle, "TU/e-OED ");
  strcat(fulltitle,title);
  var2window(fulltitle, 10000e-6, 10000e-6, 625e-6, 500e-6, 250e-6, 2250e-6,
      0.8, 100e-6, 1000e-6);
}

/* Previous varwindow function now maps onto var2window() */
void varwindow(
    const char *title,
    double s_len,      /* length of side of usable space of chip */
    double marg,       /* white margin space directly around the usable space */
                       /* defined by s_len, and before the blocks */
    double b_wid,      /* width of blocks around the usable space */
    double o_b_wid,    /* width of the furtherest out blocks */
    double o_marg,     /* distance out to the four furtherest out blocks */
    double blenprop,   /* proportion of s_len covered by the side block */
    double txt_off,    /* gap between text bottom & furtherest out squares */
    double txt_height  /* height of text */
    ) {

  var2window(title, s_len, s_len, marg, b_wid, o_b_wid, o_marg, blenprop,
      txt_off, txt_height);
}

void var2window(
    const char *title,
    double s_len,      /* length of side of usable space of chip */
    double s_height,   /* height of usable space of chip */
    double marg,       /* white margin space directly around the usable space */
                       /* defined by s_len, and before the blocks */
    double b_wid,      /* width of blocks around the usable space */
    double o_b_wid,    /* width of the furtherest out blocks */
    double o_marg,     /* distance out to the four furtherest out blocks */
    double blenprop,   /* proportion of s_len covered by the side block */
    double txt_off,    /* gap between text bottom & furtherest out squares */
    double txt_height  /* height of text */
    ) {

  double  b_len, b_height;

  push_cp();
  
  /* first the 4 small squares at the corners that are furtherest out */
  org(-(o_marg+o_b_wid/2.0), -(o_marg+o_b_wid/2.0), 0.0,NOFLIP);
  rect(o_b_wid, o_b_wid, 5,5);
  org((o_marg+o_b_wid/2.0)+s_len, -(o_marg+o_b_wid/2.0), 0.0,NOFLIP);
  rect(o_b_wid, o_b_wid, 5,5);  
  org(-(o_marg+o_b_wid/2.0),(o_marg+o_b_wid/2.0)+s_height, 0.0,NOFLIP);  
  rect(o_b_wid, o_b_wid, 5,5);  
  org((o_marg+o_b_wid/2.0)+s_len,(o_marg+o_b_wid/2.0)+s_height, 0.0,NOFLIP);    
  rect(o_b_wid, o_b_wid, 5,5);    
  
  /* now the four larger squares that are closer in and larger */
  org(-(marg+b_wid/2.0), -(marg+b_wid/2.0), 0.0,NOFLIP);
  rect(b_wid, b_wid, 5,5);
  org((marg+b_wid/2.0)+s_len, -(marg+b_wid/2.0), 0.0,NOFLIP);
  rect(b_wid, b_wid, 5,5);  
  org(-(marg+b_wid/2.0),(marg+b_wid/2.0)+s_height, 0.0,NOFLIP);  
  rect(b_wid, b_wid, 5,5);  
  org((marg+b_wid/2.0)+s_len,(marg+b_wid/2.0)+s_height, 0.0,NOFLIP);    
  rect(b_wid, b_wid, 5,5);    
 
  /* now the four long thick blocks along each side */
  /* need to find the length of the blocks */
  b_len=s_len*blenprop;
  b_height=s_height*blenprop;
  
  org((s_len/2.0),-(marg+b_wid/2.0),0.0,NOFLIP);
  rect(b_len,b_wid,5,5);
  org((s_len/2.0),(marg+b_wid/2.0)+s_height,0.0,NOFLIP);
  rect(b_len,b_wid,5,5);
  org(-(marg+b_wid/2.0),(s_height/2.0),0.0,NOFLIP);
  rect(b_wid,b_height,5,5);
  org((marg+b_wid/2.0)+s_len,(s_height/2.0),0.0,NOFLIP);
  rect(b_wid,b_height,5,5);  

  org(-(o_marg+o_b_wid/2.0),(s_height+o_marg+o_b_wid+txt_off),0.0,NOFLIP);
  textout(title,txt_height);

  pop_cp();
}
